<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px">
      <el-form-item label="企业负责人" prop="factoryChairman">
        <el-input
          v-model="queryParams.factoryChairman"
          placeholder="请输入企业负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业分管安全负责人" prop="secrutyChairman">
        <el-input
          v-model="queryParams.secrutyChairman"
          placeholder="请输入企业分管安全负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业安管机构负责人" prop="secrutyDepartmentChairman">
        <el-input
          v-model="queryParams.secrutyDepartmentChairman"
          placeholder="请输入企业安管机构负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人" prop="legalPerson">
        <el-input
          v-model="queryParams.legalPerson"
          placeholder="请输入法人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人份证号" prop="legalPersonId">
        <el-input
          v-model="queryParams.legalPersonId"
          placeholder="请输入法人份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['factorymanagement:emergencyInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['factorymanagement:emergencyInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['factorymanagement:emergencyInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['factorymanagement:emergencyInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="emergencyInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="企业负责人" align="center" prop="factoryChairman" />
      <el-table-column label="企业负责人手机号" align="center" prop="factoryChairmanPhone" />
      <el-table-column label="企业分管安全负责人" align="center" prop="secrutyChairman" />
      <el-table-column label="企业分管安全负责人手机号" align="center" prop="secrutyChairmanPhone" />
      <el-table-column label="企业安管机构负责人" align="center" prop="secrutyDepartmentChairman" />
      <el-table-column label="企业安管机构负责人手机号" align="center" prop="secrutyDepartmentChairmanPhone" />
      <el-table-column label="法人" align="center" prop="legalPerson" />
      <el-table-column label="法人份证号" align="center" prop="legalPersonId" />
      <el-table-column label="法人手机号" align="center" prop="legalPersonPhone" />
      <el-table-column label="特种作业人数" align="center" prop="specialOperationPersonNum" />
      <el-table-column label="安全生产管理人员人数" align="center" prop="secruityManagementPersonNum" />
      <el-table-column label="剧毒化学品从业人数" align="center" prop="poisonousChemistryPersonNum" />
      <el-table-column label="危险化学品作业人数" align="center" prop="dangerousChemistryPersonNum" />
      <el-table-column label="注册安全工程师人数" align="center" prop="registeredSecutiyEngineerNum" />
      <el-table-column label="应急救援队专职人数" align="center" prop="emergencyPersonNum" />
      <el-table-column label="应急救援队兼职人数" align="center" prop="emergecyParttimePersonNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['factorymanagement:emergencyInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['factorymanagement:emergencyInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改应急信息登记对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="企业负责人" prop="factoryChairman">
          <el-input v-model="form.factoryChairman" placeholder="请输入企业负责人" />
        </el-form-item>
        <el-form-item label="企业负责人手机号" prop="factoryChairmanPhone">
          <el-input v-model="form.factoryChairmanPhone" placeholder="请输入企业负责人手机号" />
        </el-form-item>
        <el-form-item label="企业分管安全负责人" prop="secrutyChairman">
          <el-input v-model="form.secrutyChairman" placeholder="请输入企业分管安全负责人" />
        </el-form-item>
        <el-form-item label="企业分管安全负责人手机号" prop="secrutyChairmanPhone">
          <el-input v-model="form.secrutyChairmanPhone" placeholder="请输入企业分管安全负责人手机号" />
        </el-form-item>
        <el-form-item label="企业安管机构负责人" prop="secrutyDepartmentChairman">
          <el-input v-model="form.secrutyDepartmentChairman" placeholder="请输入企业安管机构负责人" />
        </el-form-item>
        <el-form-item label="企业安管机构负责人手机号" prop="secrutyDepartmentChairmanPhone">
          <el-input v-model="form.secrutyDepartmentChairmanPhone" placeholder="请输入企业安管机构负责人手机号" />
        </el-form-item>
        <el-form-item label="法人" prop="legalPerson">
          <el-input v-model="form.legalPerson" placeholder="请输入法人" />
        </el-form-item>
        <el-form-item label="法人份证号" prop="legalPersonId">
          <el-input v-model="form.legalPersonId" placeholder="请输入法人份证号" />
        </el-form-item>
        <el-form-item label="法人手机号" prop="legalPersonPhone">
          <el-input v-model="form.legalPersonPhone" placeholder="请输入法人手机号" />
        </el-form-item>
        <el-form-item label="特种作业人数" prop="specialOperationPersonNum">
          <el-input v-model="form.specialOperationPersonNum" placeholder="请输入特种作业人数" />
        </el-form-item>
        <el-form-item label="安全生产管理人员人数" prop="secruityManagementPersonNum">
          <el-input v-model="form.secruityManagementPersonNum" placeholder="请输入安全生产管理人员人数" />
        </el-form-item>
        <el-form-item label="剧毒化学品从业人数" prop="poisonousChemistryPersonNum">
          <el-input v-model="form.poisonousChemistryPersonNum" placeholder="请输入剧毒化学品从业人数" />
        </el-form-item>
        <el-form-item label="危险化学品作业人数" prop="dangerousChemistryPersonNum">
          <el-input v-model="form.dangerousChemistryPersonNum" placeholder="请输入危险化学品作业人数" />
        </el-form-item>
        <el-form-item label="注册安全工程师人数" prop="registeredSecutiyEngineerNum">
          <el-input v-model="form.registeredSecutiyEngineerNum" placeholder="请输入注册安全工程师人数" />
        </el-form-item>
        <el-form-item label="应急救援队专职人数" prop="emergencyPersonNum">
          <el-input v-model="form.emergencyPersonNum" placeholder="请输入应急救援队专职人数" />
        </el-form-item>
        <el-form-item label="应急救援队兼职人数" prop="emergecyParttimePersonNum">
          <el-input v-model="form.emergecyParttimePersonNum" placeholder="请输入应急救援队兼职人数" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEmergencyInfo, getEmergencyInfo, delEmergencyInfo, addEmergencyInfo, updateEmergencyInfo } from "@/api/factorymanagement/emergencyInfo";

export default {
  name: "EmergencyInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 应急信息登记表格数据
      emergencyInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryChairman: null,
        secrutyChairman: null,
        secrutyDepartmentChairman: null,
        legalPerson: null,
        legalPersonId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        factoryChairman: [
          { required: true, message: "企业负责人不能为空", trigger: "blur" }
        ],
        factoryChairmanPhone: [
          { required: true, message: "企业负责人手机号不能为空", trigger: "blur" }
        ],
        secrutyChairman: [
          { required: true, message: "企业分管安全负责人不能为空", trigger: "blur" }
        ],
        secrutyChairmanPhone: [
          { required: true, message: "企业分管安全负责人手机号不能为空", trigger: "blur" }
        ],
        secrutyDepartmentChairman: [
          { required: true, message: "企业安管机构负责人不能为空", trigger: "blur" }
        ],
        secrutyDepartmentChairmanPhone: [
          { required: true, message: "企业安管机构负责人手机号不能为空", trigger: "blur" }
        ],
        legalPerson: [
          { required: true, message: "法人不能为空", trigger: "blur" }
        ],
        legalPersonId: [
          { required: true, message: "法人份证号不能为空", trigger: "blur" }
        ],
        legalPersonPhone: [
          { required: true, message: "法人手机号不能为空", trigger: "blur" }
        ],
        specialOperationPersonNum: [
          { required: true, message: "特种作业人数不能为空", trigger: "blur" }
        ],
        secruityManagementPersonNum: [
          { required: true, message: "安全生产管理人员人数不能为空", trigger: "blur" }
        ],
        poisonousChemistryPersonNum: [
          { required: true, message: "剧毒化学品从业人数不能为空", trigger: "blur" }
        ],
        dangerousChemistryPersonNum: [
          { required: true, message: "危险化学品作业人数不能为空", trigger: "blur" }
        ],
        registeredSecutiyEngineerNum: [
          { required: true, message: "注册安全工程师人数不能为空", trigger: "blur" }
        ],
        emergencyPersonNum: [
          { required: true, message: "应急救援队专职人数不能为空", trigger: "blur" }
        ],
        emergecyParttimePersonNum: [
          { required: true, message: "应急救援队兼职人数不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询应急信息登记列表 */
    getList() {
      this.loading = true;
      listEmergencyInfo(this.queryParams).then(response => {
        this.emergencyInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryChairman: null,
        factoryChairmanPhone: null,
        secrutyChairman: null,
        secrutyChairmanPhone: null,
        secrutyDepartmentChairman: null,
        secrutyDepartmentChairmanPhone: null,
        legalPerson: null,
        legalPersonId: null,
        legalPersonPhone: null,
        specialOperationPersonNum: null,
        secruityManagementPersonNum: null,
        poisonousChemistryPersonNum: null,
        dangerousChemistryPersonNum: null,
        registeredSecutiyEngineerNum: null,
        emergencyPersonNum: null,
        emergecyParttimePersonNum: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加应急信息登记";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEmergencyInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改应急信息登记";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEmergencyInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEmergencyInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除应急信息登记编号为"' + ids + '"的数据项？').then(function() {
        return delEmergencyInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('factorymanagement/emergencyInfo/export', {
        ...this.queryParams
      }, `emergencyInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>